package wang;

import cn.hutool.core.date.DateUtil;
import org.apache.poi.ss.usermodel.*;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.*;


public class ImportData {


    public static final String ADD_DATA_URL = "http://121.237.33.12:58088/cc/cc/cc001/WorkListAddSave.do";

    public static void main(String[] args) throws Exception {
    	
    	Scanner sc =new Scanner(System.in);
    	System.out.println("请输入 JSESSIONID：");
    	String cookieStrIN=" "+sc.nextLine().trim();
    	System.out.println("请复制模板路径：");
    	String filePath=sc.nextLine().trim();
    	
//        String cookieStr =" JSESSIONID=59E6246902F22E345B4BCEA8DE82D0D0";
//        getDataForFile( cookieStr, "D:\\A_Eclipse_WorkSpace\\填工单.xlsx");
        
        String cookieStr =" JSESSIONID=E2C78FB2779B282DB22A6EE3FD79E8C4";
        getDataForFile( new String(cookieStrIN.getBytes(),"UTF-8"), new String(filePath.getBytes(),"UTF-8"));
        
       
    }



    //获取所有表格文件信息
    public static void getDataForFile(String cookieStr,String path) throws IOException {
        String classPath ="";
        File fileName = new File(path);
        if(!(fileName.isFile()&&fileName.exists())){
         return ;
        }
        List<String> resultList = new ArrayList<>();
        Workbook workbook =null;
        FileInputStream fs = null;
        try {
            fs = new FileInputStream(fileName);
            workbook = WorkbookFactory.create(fs);
        } catch (Exception e) {
            e.printStackTrace();
        }
            Sheet sheet_source = null;
            sheet_source = workbook.getSheetAt(0);
            Cell cell = null;
            int rowNum=0;
            String todayTime =DateUtil.format(new Date(),"yyyy-MM-dd"), personName =null,personName_KH =null,progromType =null,xiangx_content =null,resove=null,sysPt="报账平台(财务)";

            for (Row r:sheet_source) {
                // 略过标题行
                if (r.getRowNum() < 1) {
                    continue;
                }
                rowNum++;
                int colIdx = 0;
                
                if(r.getCell(3)==null&&r.getCell(4)==null) {
                	continue;
                }
                
                xiangx_content=r.getCell(3).getStringCellValue();

                resove=r.getCell(4).getStringCellValue();

                String  cellTime=todayTime +" "+ r.getCell(6).getStringCellValue().substring(11);


                // personName_KH=r.getCell(7).getStringCellValue();


                //-----------拼接参数
                Map<String, Object> paramMap = null;
                paramMap = new HashMap<>();

                paramMap.put("WL_SA_ID", "746");

                paramMap.put("ROLE_CODE", "[CC_AGENT]");

                paramMap.put("WL_SYSTEM", 11);

                paramMap.put("WL_MODULE_ID", 1101);
                //日期
                paramMap.put("WL_DATETIME", cellTime);

                paramMap.put("WL_CUSTOMER_ID", 2);

                paramMap.put("WL_ACCEPTER_ID", 956822);

                paramMap.put("WL_CONSULTANT_ID", 956822);

                paramMap.put("WL_ACCESS", 2);

                paramMap.put("WL_SERVICE_TYPE_LEVEL_1", 1);

                paramMap.put("WL_SERVICE_TYPE", 11);
                //问题
                paramMap.put("WL_PROBLEM", xiangx_content);
                // 解决方案
                paramMap.put("WL_SOLUTION", resove);
                //场景分析标签
                paramMap.put("WL_SCENE_ANALYSIS", "报账业务咨询");

                paramMap.put("WL_ACTUAL_TIME", 5);

                paramMap.put("WL_IS_RESOLVED", 1);

                paramMap.put("WL_IS_MULTISPECIALTY", 0);

                paramMap.put("WL_RESULT", 1);

                paramMap.put("WL_COMMIT_2ND_TIER", 0);

                //不重要的
                paramMap.put("WL_ID", "");
                paramMap.put("PROCESS_ID", "");
                paramMap.put("WL_CALL_ID", "");
                paramMap.put("WL_PLANNED_TIME", "");

                paramMap.put("WL_ITSM_ID", "");

                paramMap.put("WL_FAILURE_TIMES", "");

                paramMap.put("ATTACHMENT_FILES", "");

                String toData = "";

                Set<String> keys = paramMap.keySet();

                for (String key : keys) {
                    toData += key + "=" + paramMap.get(key) + "&";

                }
                toData = toData.substring(0, toData.lastIndexOf("&"));
                System.out.println(ADD_DATA_URL +"?"+toData);
                resultList.add(toData);
            }
         int succ =0;
        for (int i = 0; i < resultList.size(); i++) {
        HttpRequestUtil.sendPost3(cookieStr, ADD_DATA_URL, resultList.get(i));
        succ ++;
        }
        
        System.out.println("成功导入条数："+succ);

    }


}


